lib/prune: Don't modify dirent->d_name in place
authorMatthew Leeds <matthew.leeds@endlessm.com>
Thu, 14 Jun 2018 21:33:10 +0000 (14:33 -0700)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 15 Jun 2018 19:01:46 +0000 (19:01 +0000)
commit7dc3e45b3a2a0946182159121d2d3b7d7b938697
tree55f0dff2620c1f74c3ef074478e57b8c44e703b6
parent677e1810254685a1ec34679c5b1f5324236b091d
lib/prune: Don't modify dirent->d_name in place

Currently when I run `ostree prune` it hits a seg fault when the
hash_func is used (in this case g_str_hash) from the call stack
_ostree_repo_prune_tmp() -> g_hash_table_contains() ->
g_hash_table_lookup_node(). So the key, in this case dent->d_name, must
be corrupt in some way.

glnx_dirfd_iterator_next_dent() uses readdir() to get the dirent struct.
And according to the man page for readdir(3), "POSIX.1 explicitly notes
that this field should not be used as an lvalue" (in reference to
d_name). So this commit avoids modifying d_name in place and copies it
instead. This seems to avoid the seg fault.

Closes: #1627
Approved by: jlebon
src/libostree/ostree-repo-prune.c